

class StateMachine:
    
    def __init__(self):
        self.states = {}
    
    def add(self, state):
        if not self.states.has_key(state.priority):
            self.states[state.priority] = []
        self.states[state.priority].append(state)
        
    def update(self):
        for priority in self.states:
            for state in self.states[priority]:
                if state.running:
                    if state.shouldContinue():
                        state.update()
                elif state.shouldStart():
                    state.running = True
                    state.onStart()
                    state.update()
                else:
                    state.running = False
        return False
                

class State:
    
    def __init__(self, priority, entity):
        self.priority = priority
        self.entity = entity
        self.running = False
    
    def shouldStart(self):
        return False
    
    def shouldContinue(self):
        return False
    
    def onStart(self):
        pass
    
    def update(self):
        pass